/*
 * Copyright (c) 2013 - 2015, Freescale Semiconductor, Inc.
 * Copyright 2016-2017, 2024 NXP
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "fsl_device_registers.h"
#include "fsl_debug_console.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "board.h"
#include "cm_backtrace.h"
#include "softspi.h"
/*******************************************************************************
 * Definitions
 ******************************************************************************/


/*******************************************************************************
 * Prototypes
 ******************************************************************************/

/*******************************************************************************
 * Variables
 ******************************************************************************/

/*******************************************************************************
 * Code
 ******************************************************************************/
/*!
 * @brief Main function
 */
 void fault_test_by_div0(void)
{
    volatile int * SCB_CCR = (volatile int *) 0xE000ED14; // SCB->CCR
    int x, y, z;

    *SCB_CCR |= (1 << 4); /* bit4: DIV_0_TRP. */

    x = 10;
    y = 0;
    z = x / y;
    PRINTF("z:%d\n", z);
}

void test (void)
{
	fault_test_by_div0();
}
extern void LCD_Clear(unsigned int Color);
extern void st7735_test(void);
extern void IO_Tester(void);
extern int32_t Disp0_DrawBitmap(uint32_t x, uint32_t y, uint32_t width, uint32_t height, const uint8_t *bitmap);
uint16_t s_framebuf[128*128] = {0};
uint64_t tick = 0;
//int64_t arm_2d_helper_get_system_timestamp(void)
//{
//	return tick;
//}
//uint32_t arm_2d_helper_get_reference_clock_frequency(void)
//{
//	
//}

void SysTick_Handler(void)
{
	tick++;
}
void IO_Tester(void);

void NxpLpspiInit(void);

int main(void)
{
    char ch;
	cm_backtrace_init("hello_world","1.0","1.0");
    /* Init board hardware. */
    BOARD_ConfigMPU();
    BOARD_InitBootPins();
    BOARD_InitBootClocks();
    BOARD_InitDebugConsole();
	
    /* Just enable the trace clock, leave coresight initialization to IDE debugger */
    SystemCoreClockUpdate();
    CLOCK_EnableClock(kCLOCK_Trace);
	SysTick_Config(SystemCoreClock / (1 * 1000U));
	MySPI_Init();
    NxpLpspiInit();

	LCD_Init();
	LCD_Clear(0xffff);
	//IO_Tester();
	memset(s_framebuf,0x22,sizeof(s_framebuf));
	Disp0_DrawBitmap(0,0,64,64,(uint8_t*)s_framebuf);

	//st7735_test();
    while (1)
    {

    }
}
